'use strict';

var easy_web_ui_module = angular.module('easy.web.ui', ["ui.bootstrap", "easy.web.services"])
    .directive("ezNavBar", function () {
        return {
            restrict: 'EAC',
            templateUrl: ezStaticResource("/static/default/template/","navBar.html"),
            replace: true,
            scope: {
                title: '@'
            },
            controller: function ($scope, $http, userService,easyService) {

                easyService.addCss("/static/default/css/","navBar.css");

                $scope.display = {};
                $scope.display.title = $scope.title;
                $scope.display.root = easyService.appROOT();
                $scope.display.img = easyService.staticResource("/static/default/image/","menu-toggler.png");
                $scope.display.username = "";
                $scope.logout = function () {
                    userService.logout();
                };
                $scope.changePassword = function () {
                    userService.changePassword(function () {
                    }, function () {
                    });
                };

                userService.current(function (response) {
                    console.log(response);
                    var username = response.username;
                    var realName = response.realName;
                    if (realName == undefined || realName == null) {
                        realName = 'null';
                    }

                    $scope.display.username = realName + '(' + username + ')';
                })

            }
        };
    })

    .directive("ezSideBar", function () {
        return {
            restrict: 'EAC',
            templateUrl: APP_ROOT + "/static/default/template/sideBar.html",
            replace: true,

            controller:function ($scope, $http, systemService,easyService){

                $('body').addClass("page-header-fixed");

                easyService.addCss("/static/default/css/","sideBar.css");

                $scope.page_sidebar_class = ['navbar-collapse', 'collapse', 'page-sidebar'];

                $scope.on_click_page_sidebar_toggler = function () {
                    var b = $("body");
                    if (b.hasClass("page-sidebar-closed")) {
                        b.removeClass("page-sidebar-closed");
                    } else {
                        b.addClass("page-sidebar-closed");
                    }

                };

                systemService.currentUserModules(function(response){
                    for (var i=0;i<response.length;i++){
                        var module = response[i];
                        module.active = false;
                        for (var j=0;j<module.items.length;j++){
                            var item = module.items[j];
                            item.url = APP_ROOT+ module.url+ item.url;
                        }
                    }
                    $scope.items = response;
                })

            }

        };
    })
    ;



